local sk__jinglun = fk.CreateSkill {

  name = "sk__jinglun",

  tags = {  },

}



sk__jinglun:addEffect(fk.CardUsing, {
  name = "sk__jinglun",
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__jinglun.name) and data.responseToEvent and player:usedSkillTimes(sk__jinglun.name, Player.HistoryTurn) == 0 then
      if target == player then
        return data.responseToEvent.from ~= player and data.toCard and
          player.room:getCardArea(data.toCard) == Card.Processing
      else
        return data.responseToEvent.from == player and data.responseToEvent.card and
          player.room:getCardArea(data.card) == Card.Processing
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local card
    if target == player then
      card = data.toCard
    else
      card = data.card
    end
    return player.room:askForSkillInvoke(player, sk__jinglun.name, nil, "#sk__jinglun-invoke:::"..card:toLogString())
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if target == player then
      room:moveCardTo(data.toCard, Card.PlayerHand, player, fk.ReasonPrey, sk__jinglun.name, nil, true, player)
    else
      room:moveCardTo(data.card, Card.PlayerHand, player, fk.ReasonPrey, sk__jinglun.name, nil, true, player)
    end
  end,
})
sk__jinglun:addEffect(fk.CardResponding, {
  name = "sk__jinglun",
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__jinglun.name) and data.responseToEvent and player:usedSkillTimes(sk__jinglun.name, Player.HistoryTurn) == 0 then
      if target == player then
        return data.responseToEvent.from ~= player and data.responseToEvent.toCard and
          player.room:getCardArea(data.responseToEvent.toCard) == Card.Processing
      else
        return data.responseToEvent.from == player and data.responseToEvent.card and
          player.room:getCardArea(data.card) == Card.Processing
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local card
    if target == player then
      card = data.responseToEvent.toCard
    else
      card = data.card
    end
    return player.room:askForSkillInvoke(player, sk__jinglun.name, nil, "#sk__jinglun-invoke:::"..card:toLogString())
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if target == player then
      room:moveCardTo(data.responseToEvent.toCard, Card.PlayerHand, player, fk.ReasonPrey, sk__jinglun.name, nil, true, player)
    else
      room:moveCardTo(data.card, Card.PlayerHand, player, fk.ReasonPrey, sk__jinglun.name, nil, true, player)
    end
  end,
})

return sk__jinglun